#include "Goto.h"
#include <QDebug>

Goto::Goto(QWidget *parent) : QDialog(parent), ui(new Ui::Goto) {
    ui->setupUi(this);
}

Goto::~Goto() {
    delete ui;
}

void Goto::on_GotoPushButton_clicked() {
    qDebug() << "GotoPushButton clicked";
    QString lineStr = ui->GotoLineEdit->text();
    bool toIntOk = false;
    int line = lineStr.toInt(&toIntOk);
    // 对输出进行校验，如果时大于0的整数，发送信号；否则，清空lineEdit重新输入
    if(toIntOk && line > 0){
        emit gotoLine(line);
    } else {
        ui->GotoLineEdit->clear();
        ui->GotoLineEdit->setFocus();
    }
}

void Goto::on_CancelPushButton_clicked(){
    qDebug() << "CancelPushButton clicked";
    close();
}

void Goto::showEvent(QShowEvent *event) {
    qDebug() << "showEvent";
    // 清空lineEdit，并设置Focus
    ui->GotoLineEdit->clear();
    ui->GotoLineEdit->setFocus();
}